$(function(){
   var act_title=sessionStorage.getItem("act_title");
   var act_level_name=sessionStorage.getItem("act_level_name");
//   var act_level=sessionStorage.getItem("act_level");
//   var token=sessionStorage.getItem("token");
//   var method="get_pay_type";
   $("#act_title").html(act_title);
   $("#act_level_name").html(act_level_name);
    $.ajax({
        type:"post",
        url:"http://www.rice.com/app/api/h5_access",
        data:{method:"level_data"},
        dataType:"json",
        success:function(result){
            if(result.status=="1"){
                var data=result.data.data;
                var sttr="";
                for(var i in data){
                    var dis=data[i].is_act;
                    if(dis=="0"){
                        sttr+=' <a onclick="javascript:tanc(this);" style="cursor:pointer;display:none;" data-level="'+data[i].level+'" data-name="'+data[i].act_name+'">';
                    }else{
                        sttr+=' <a onclick="javascript:tanc(this);" style="cursor:pointer;" data-level="'+data[i].level+'" data-name="'+data[i].act_name+'">';
                    }
                    sttr+='<div style="padding:20px 10px 20px 10px;"><div clas="am-u" ><div class="am-u-sm-12" style="padding: 20px 10px 20px 10px;background: #fff;border-radius: 15px;">';
                    sttr+=' <div class="am-u-sm-5" style="text-align: center;"><img src="'+data[i].act_img+'" alt=""  style="width: 40px;"/><p style="font-size: 16px;color:#333">'+data[i].act_name+'</p></div>';                                    
                     sttr+='<div class="am-u-sm-7" ><div style="font-size: 15px;color:#333">'+data[i].act_description+'</div></div>';          
                     sttr+='</div></div></div>';
                     sttr+='</a><div style="clear:both;"></div>';
                }
                $(".act_table").html(sttr);
            }else if(result.status=="2"){
                alert(result.message);
                location.href="login.html";
            }else{
                alert(result.message);
            }
        }
    })

})
   
   function actClick(obj){
        var act_level_name=$(obj).attr("data-name");
        var act_level=$(obj).attr("data-level");
        var token=sessionStorage.getItem("token");
        var  che=$(obj).attr("data-chan");
        var d={};
      d.method="get_upgrade_activity_url";
      d.token=token;
      d.level=act_level;
      d.level_name=act_level_name;
      d.type=che;
     $.ajax({
         type:"post",
         url:"http://www.rice.com/app/api/h5_access",
         data:d,
         dataType:"json",
         success:function(result){
             if(result.status=="1"){
                var data=result.data;
                sessionStorage.setItem("url1",data.url);
                sessionStorage.setItem("money",data.money);
                sessionStorage.setItem("code_num_upgrade",data.code_num_upgrade);
                sessionStorage.setItem("trade_no",data.trade_no);
                sessionStorage.setItem("channel",data.channel);
                 if(data.channel=="unionpay"){//银联
    
                      location.href=data.url;
                 }else{
  
                     location.href="ewma.html";
                 }
             }else if(result.status=="2"){
                alert(result.message);
                location.href="login.html";
            }else{
                alert(result.message);
            }
         }
     })
   }

   function tanc(obj){
            var act_level_name=$(obj).attr("data-name");
            var act_level=$(obj).attr("data-level");
            $.ajax({
                type:"post",
                url:"http://www.rice.com/app/api/h5_access",
                data:{method:"get_pay_type"},
                dataType:"json",
                success:function(result){
                    if(result.status=="1"){
                        layer.open({
                             type: 1,
                             offset: 'b' ,
                             content: '<div style="width:200px;height:auto;"><ul id="tan-con" class="am-list h35"></ul></div>',
                             btn: '关闭全部',
                             btnAlign: 'c',
                             shade: 1 ,
                             yes: function(){
                               layer.closeAll();
                             }
                           });
                           
                        var data=result.data.data;
                        var sttr="";
 
                        for(var i in data){
                            sttr+="<li data-chan="+data[i].channel+" class='h35' style='cursor:pointer;height:35px;line-height:35px;' onclick='javascript:actClick(this);' data-name='"+act_level_name+"'data-level='"+act_level+"'>";
                            sttr+="<img src='"+data[i].img_url+"' width='30px'/>";
                            sttr+="<sapn style='width:70%;text-align:center;display:inline-block;'>"+data[i].name+"</span>";
                            sttr+="</li>";
                        }
                        $("#tan-con").html(sttr);
  
                    }else if(result.status=="2"){
                        alert(result.message);
                        location.href="login.html";
                    }else{
                        alert(result.message);
                    }
                }
            })

   }
     